
//页面内执行
function pageinit () {
//弹窗切换功能

	$(function () {
		var _pop =  $('.page02 .box_pop');
		var _btn = $('.page02 .btn');
		var _box_btn = $('.page02 .box_btn');
		var _txt_all = $('.page02 .box_pop .txt');
		_pop.hide();
		_txt_all.hide();
		_btn.on('click',function(){
			_box_btn.css({'opacity':'0','height':0,'min-height':'0'});
			//_box_btn.hide();
			var _tit = $(this).data('tit');
			var _index = $(this).data('index');
			_pop.show();
			_pop.find('.tit').text(_tit);
			_pop.find('.txt').eq(_index).show();
		});
		$('.page02 .close_btn').on('click',function(e){
			e.stopPropagation();
			_pop.hide();
			_pop.find('.txt').hide();
			_box_btn.css({'opacity':'1','height':'auto','min-height':'auto'});

			// _box_btn.show();
			_pop.find('.tit').text(" ");
		})
		//尾页提交弹窗
		$('.page07 .tip.btn').on('click', function(){
			$('.pop_tip').css({'opacity':'1','display':'block'});
			setTimeout(function () {
				$('.pop_tip').hide()
			}, 2000);
		});

		$('.txt_wrapper').on('touchstart touchmove touchend',function(e){
			e.stopPropagation()
		});

		var pagefocus = false;
		var pageresizeonOff = false;
		$('.page07 input.tip').on('focus', function(){
			$('.page07 .box-1').hide();
			pagefocus = true;
		});
		$('.page07 input.tip').on('blur', function(){
			$('.page07 .box-1').show();
			pagefocus = false;
		});
		$('.box_btn').on('touchstart',function(){
			$('.box_btn .pop-cloud').remove();
		})
		$(window).on('resize',function(){
			if(pagefocus&&pageresizeonOff){
				$('.page07 .box-1').show();
			}
			pageresizeonOff = !pageresizeonOff
		})
	});



}
pageinit();

function pageShow(){
	var swiperLength = $('.page').length;
	var mySwiper = new Swiper ('.swiper-container', {
		direction: 'vertical',
		loop: false,
		speed:500,
		on:{
			init: function(){
				swiperAnimateCache(this); //隐藏动画元素
				swiperAnimate(this); //初始化完成开始动画
				$('.load-wrapper').hide();
			},
			slideChangeTransitionEnd: function() {
				swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
				swiperAnimatenoHide(this);
				if (this.activeIndex === swiperLength-1) {
					$('.swiper-button-next').css({'display': 'none'})
				} else {
				$('.swiper-button-next').css({'display': ''})
				}
			}

		},
		navigation: {
			nextEl: '.swiper-button-next'
		}
	});

}

function audioCheck () {
	var _audioPlayer = document.getElementById('audioMain');
	if (_audioPlayer.paused){
		_audioPlayer.play();
		$(".icon-audio").addClass('turnAroundQuick stop');
	}else{
		_audioPlayer.pause();
		$(".icon-audio").removeClass('turnAroundQuick stop');
	}
}

//pxloader
// var baseUrl = './img/',
// 	imgLoader = new PxLoader();
// for(var i=0; i < imgArr.length; i++) {
// 	var pxImage = new PxLoaderImage(baseUrl + imgArr[i]);
// 	pxImage.imageNumber = i + 1;
//
// 	imgLoader.add(pxImage);
// }
// imgLoader.addCompletionListener(function(e){
// 	imgFin = true;
//
// });
// imgLoader.start(pxImage);

//音频操作
$(function () {
	var _audiofirload = true;
	var audioPlayer = document.getElementById('audioMain');
	// audioPlayer.play();
	if(!audioPlayer.paused){
		$('.icon-audio').addClass('turnAroundQuick stop');
	}

	$('.icon-audio').on('touchstart',function(e){
		e.stopPropagation();
		firswitchAuido = true;
		_audiofirload = false;
		if (audioPlayer.paused){
			// audioPlayer.load();
			audioPlayer.play();
			$(this).addClass('turnAroundQuick stop');
		}else{
			audioPlayer.pause();
			$(this).removeClass('turnAroundQuick stop');
		}
	});

});
var audioPlayer = document.getElementById('audioMain');
// 展示页面启动
var canshow = setInterval(function(){

	if(imgFin){

		$('.audio-main').attr('autoplay','autoplay');
		audioPlayer.load();
		$('.swiper-container').append(strMain);
		pageinit();
		$('.page01').on('touchstart',function(){
			if(firTouch === false){
				firTouch = true;
				if (audioPlayer.paused&&firswitchAuido===false){
					audioPlayer.play();
					$('.icon-audio').addClass('turnAroundQuick stop');
				}else{
					return false;
				}
			}
		});
		firplay = function(){
			audioPlayer.play();
			document.removeEventListener("touchstart",firplay, false);
		};
		document.addEventListener("touchstart",firplay, false);
		firplay();

		if(audioPlayer.paused){
			audioPlayer.load();
			firplay();
		}
		$('.icon-audio').addClass('turnAroundQuick stop');
		setTimeout(function(){
			pageShow();  //自定义页面加载方法
		},200);
		clearInterval(canshow);
	}
},300);

